package com.business.yang.mvp.view.home.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.business.yang.R;
import com.business.yang.core.BaseMainActivity;
import com.lyxs916.adapter.ViewHolder;
import com.lyxs916.adapter.recyclerview.CommonAdapter;
import com.lyxs916.adapter.recyclerview.click.OnItemClickListener;
import com.lyxs916.appbaselibrary.core.presenter.BasePresenter;
import com.lyxs916.testlibrary.downding.DownloadingActivity;
import com.lyxs916.testlibrary.loadingtest.LoadingBarActivity;
import com.lyxs916.testlibrary.recyclertest.ListTestActivity;
import com.lyxs916.testlibrary.recyclertest.ListTestActivity2;
import com.lyxs916.testlibrary.recyclertest.RefreshTestActivity;
import com.lyxs916.testlibrary.rxjavatest.TRRMainActivity;
import com.lyxs916.testlibrary.uploding.UplodingActivity;
import com.lyxs916.testlibrary.viewpagerframent.FragmentManagerActivity;
import com.lyxs916.utilslibrary.ui.divider.HorizontalDividerItemDecoration;

import java.util.ArrayList;

import butterknife.BindView;

public class HomeActivity extends BaseMainActivity {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    ArrayList<String> mData = new ArrayList<>();
    CommonAdapter adapter;

    public static void startUi(Context context) {
        Intent intent = new Intent(context, HomeActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int setContentView() {
        return R.layout.activity_home;
    }

    @Override
    public void parseIntent(Intent intent) {

    }

    @Override
    public int currentItem() {
        return 0;
    }

    @Override
    public void initView() {
        super.initView();
        mData.add("rxJava_and_retrofit 测试");//0
        mData.add(" loading 测试");//1
        mData.add("自动加载RecyclerView 请求测试继承BaseMvpActivity");//2
        mData.add("自动加载RecyclerView 请求测试,继承BaseListActivity");//3
        mData.add("只刷新请求测试");//4
        mData.add("fragment请求测试");//5
        mData.add("上传文件测试");//6
        mData.add("下载文件测试");//7

        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).sizeResId(R.dimen.dp_5).colorResId(R.color.gray_ee).build());
        recyclerView.setAdapter(adapter = new CommonAdapter<String>(this, R.layout.item, mData) {
            @Override
            public void convert(ViewHolder holder, String s) {
                holder.setText(R.id.test, (holder.getmPosition() + ".") + "\t" + s);
            }
        });

        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(ViewGroup parent, View view, Object data, int position) {
                switch (position) {
                    case 0:
                        TRRMainActivity.startUi(mActivity);
                        break;
                    case 1:
                        LoadingBarActivity.startUi(mActivity);
                        break;
                    case 2:
                        ListTestActivity.startUi(mActivity);
                        break;
                    case 3:
                        ListTestActivity2.startUi(mActivity);
                        break;
                    case 4:
                        RefreshTestActivity.startUi(mActivity);
                        break;
                    case 5:
                        FragmentManagerActivity.startUI(mActivity);
                        break;
                    case 6:
                        UplodingActivity.startUi(mActivity);
                        break;
                    case 7:
                        DownloadingActivity.startUi(mActivity);
                        break;
                }
            }
        });
    }

    @Override
    public BasePresenter initPresenter() {
        return null;
    }
}
